<?php

namespace IDock\Insurance\ACIC\Response;

use IDock\Http\Response;
use IDock\Printer\PremiumUnderwritingPrinter;

class UnderwritingResponse extends AllACICResponse
{

    protected function errorTrans($error)
    {
        if (preg_match('/未上传影像，下发修改/',$error)) {

            $error .= "\r\n" . '请上传《投保人身份证》，《行驶证》，《被保人身份证》(当被保人与投保人不是同一人时)，《上年保单证明资料》(转保时需要)，《验车照》(车龄超过10年以上)，《验车报告》(车龄超过10年以上)';
        }
        return $error;

    }

    public function printerInit(): Response
    {

        $premiumUnderwritingPrinter = new PremiumUnderwritingPrinter();

        $premiumUnderwritingPrinter->inquiryNo = $this->get('ConfirmNo');

        $premiumUnderwritingPrinter->biInquiryNo = $this->get('BI')['BConfirmNo'] ?? '';

        $premiumUnderwritingPrinter->ciInquiryNo = $this->get('CI')['CConfirmNo'] ?? '';

        $biStats = $this->get('BI')['UWFlag'] ?? '2';
        $biTip = $this->get('BI')['UWMessage'] ?? '';

        $ciStats = $this->get('CI')['UWFlag'] ?? '2';
        $ciTip = $this->get('CI')['UWMessage'] ?? '';

        if ($ciStats == '2' and $biStats == '2') {
            $premiumUnderwritingPrinter->statusCode = 'U1';
        }

        if ($biStats == '1' or $ciStats == '1') {
            $premiumUnderwritingPrinter->statusCode = 'U3';
            if ($biTip or $ciTip) {
                $premiumUnderwritingPrinter->messageTip = implode("\r\n", array_filter([$biTip . $ciTip]));
            } else {
                $premiumUnderwritingPrinter->messageTip = '转人工核保';
            }
        }

        if ($biStats == '0' or $ciStats == '0') {
            $premiumUnderwritingPrinter->statusCode = 'U2';
        }

        $this->printer = $premiumUnderwritingPrinter;

        return $this;
    }
}